/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
 * };
 */
class Solution {
public:
    bool isSubStructure(TreeNode* A, TreeNode* B) {
    	return recur(A,B);
    }
private:
	bool recur(TreeNode* A, TreeNode* B){
		if(A == NULL || B == NULL) return false;
		else if(A == NULL && B==NULL) return true;

		if(A->val == B->val){
			bool left = recur(A->left,B->left);
			bool right = recur(A->right,B->right);
			return left && right;
		}
	}
};